package com.ruoyi.web.controller.llm;


import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.llm.domain.po.ProjectInfoPo;
import com.ruoyi.llm.service.ProjectInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags="应用接口")
@RestController
@RequestMapping("/llm/project")
public class ProjectInfoController extends BaseController {
    @Autowired
    private ProjectInfoService projectInfoService;

    @GetMapping("/list")
    @ApiOperation(value = "所有应用列表",response= ProjectInfoPo.class)
    public TableDataInfo projectList(String name,Integer pageNum,Integer pageSize)
    {
        startPage();
        if(pageSize == null){
            pageSize = 10;
        }
        if(pageNum == null){
            pageNum = 1;
        }
        PageHelper.startPage(pageNum,pageSize);
        List<ProjectInfoPo> ls=projectInfoService.listProjectInfo(name);
        return getDataTable(ls);
    }

    @GetMapping("/get")
    @ApiOperation(value = "根据ID获取应用详情",response= ProjectInfoPo.class)
    public AjaxResult getProject(@RequestParam("docId") String docId)
    {
        ProjectInfoPo ls=projectInfoService.getProjectInfo(docId);
        return this.success(ls);
    }


    @PostMapping("/create")
    @ApiOperation(value = "保存应用",response= ProjectInfoPo.class)
    public AjaxResult createProject(@RequestBody ProjectInfoPo proInfoPo){
        String rebakMsg = projectInfoService.createProject(proInfoPo);
        if(rebakMsg.equals("保存成功")){
            return this.success(rebakMsg);
        }else{
            return  this.error(rebakMsg);
        }

    }

    @PostMapping("/update")
    @ApiOperation(value = "保存应用",response= ProjectInfoPo.class)
    public AjaxResult updateProject(@RequestBody ProjectInfoPo proInfoPo){
        String rebakMsg = projectInfoService.updateProject(proInfoPo);
        if(rebakMsg.equals("保存成功")){
            return this.success(rebakMsg);
        }else{
            return  this.error(rebakMsg);
        }

    }
}
